﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApp.App.Models.DAL.Cms
{
    public class SysConfig
    {
        public class __GetConfigs_cfs__:NRapid.Struct
		{
			public System.String name;
			public System.String value;
			#region 写Json字符串
			public override void WriteJson(System.IO.TextWriter tw)
			{
				tw.Write("{");
						tw.Write("\"name\":");
						if(name==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(name);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"value\":");
						if(value==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(value);
							tw.Write("\"");
						}
				tw.Write("}");
			}
			#endregion
		}
		public Dictionary<string, string> GetConfigs()
        {
            var con = new System.Data.SQLite.SQLiteConnection(NRapid.Config.ConfigurationManager.ConnectionStrings["Common"].ConnectionString);
			con.Open();
            #region	var cfs;选取所有记录
			var cfs = new NRapid.List<__GetConfigs_cfs__>();
			var __GetConfigs_cfs_command__ = new System.Data.SQLite.SQLiteCommand("select name,value from sys_config", con);
			var __GetConfigs_cfs_reader__= __GetConfigs_cfs_command__.ExecuteReader();
			if (__GetConfigs_cfs_reader__.HasRows)
			{
				while (__GetConfigs_cfs_reader__.Read())
				{
					var __GetConfigs_cfs_temp__ = new __GetConfigs_cfs__();
					__GetConfigs_cfs_temp__.name =__GetConfigs_cfs_reader__.IsDBNull(0)?null: __GetConfigs_cfs_reader__.GetString(0);
					__GetConfigs_cfs_temp__.value =__GetConfigs_cfs_reader__.IsDBNull(1)?null: __GetConfigs_cfs_reader__.GetString(1);
					cfs.Add(__GetConfigs_cfs_temp__);
				}
			}
			__GetConfigs_cfs_reader__.Dispose();
			__GetConfigs_cfs_command__.Dispose();
			#endregion
			
            Dictionary<string, string> configs = new Dictionary<string, string>();
            foreach (var cf in cfs)
            {
                configs.Add(cf.name, cf.value);
            }
            con.Close();
            return configs;
        }
    }
}